<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="./template.xhtml">

    <ui:define name="title">
        Quản lý cấu hình rate
    </ui:define>

    <ui:define name="content">
        <h:form>
            <p:panel header="Quản lý Rate" id="inputForm">
                <h:panelGrid columns="2">
                    <h:outputText value="Rate Level: "/>
                    <h:selectOneMenu value="#{scratchConfigRate.level}">
                        <f:selectItem itemValue="1" itemLabel="Level 1"/>
                        <f:selectItem itemValue="2" itemLabel="Level 2"/>
                        <f:selectItem itemValue="3" itemLabel="Level 3"/>
                        <f:selectItem itemValue="4" itemLabel="Level 4"/>
                        <f:selectItem  itemValue="5" itemLabel="Level 5"/>
                    </h:selectOneMenu>
                    <h:outputText value="Nhập giá trị cận dưới " />
                    <p:inputText value="#{scratchConfigRate.bottom}"/>
                    <h:outputText value="Nhập giá trị cận trên: " />
                    <p:inputText value="#{scratchConfigRate.up}"/>
                    <h:outputText value="Nhập giá trị rate: " />
                    <p:inputText value="#{scratchConfigRate.rate}" />
                    <p:commandButton value="Cập nhật" update="listRate" ajax="false"
                                     actionListener="#{scratchConfigRate.updateRate}"/>
                    <p:messages id="messages" showDetail="true" autoUpdate="true"/> 
                </h:panelGrid>
            </p:panel>
            <p:panel header="Danh sách">
                <p:dataTable var="rates" value="#{scratchConfigRate.configs}" id="listRate" 
                             rendered="#{scratchConfigRate.configs.size()>0}">  
                    <f:facet name="header">  
                        Danh sách Rate 
                    </f:facet>  

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Rate Level" />  
                        </f:facet>  
                        <h:outputText value="#{rates.levelId}"/>  
                    </p:column>  

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Bottom Value" />  
                        </f:facet>  
                        <h:outputText value="#{rates.bottomValue}" />  
                    </p:column>  

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Up Value" />  
                        </f:facet>  
                        <h:outputText value="#{rates.upValue}" />  
                    </p:column>  

                    <p:column>  
                        <f:facet name="header">  
                            <h:outputText value="Rate Value" />  
                        </f:facet>  
                        <h:outputText value="#{rates.rate}" />  
                    </p:column>

                    <p:column>
                        <f:facet name="header">  
                            <h:outputText value="Cập nhật thông tin" />  
                        </f:facet>  
                        <p:commandButton value="Sửa" actionListener="#{scratchConfigRate.fillInput}"  ajax="false" update="inputForm">
                            <f:param name="levelId" value="#{rates.levelId}"/>
                        </p:commandButton>
                        <p:commandButton value="Xóa" action="#{scratchConfigRate.delete}" ajax="false" update="listAccount">
                            <f:param name="levelId" value="#{rates.levelId}"/>
                        </p:commandButton>
                    </p:column>

                </p:dataTable>  
            </p:panel>
        </h:form>
    </ui:define>
</ui:composition>
